/**
 * @file Layer.cpp
 *
 * @date 19/12/2011
 * @author Tales 
 *
 */

#include "Layer.hpp"
#include "../common/Error.hpp"

namespace yep
{

Layer::Layer()
{
	surface = NULL;
}

Layer::Layer(const Layer & other) /*:
		name(other.name)*/
{
	SDL_Surface *oSurface = other.surface;
	surface = SDL_ConvertSurface(oSurface, oSurface->format, oSurface->flags);
//	surface = SDL_CreateRGBSurface(oSurface->flags, oSurface->w, oSurface->h, oSurface->format->BitsPerPixel,
//			oSurface->format->Rmask, oSurface->format->Gmask, oSurface->format->Bmask, oSurface->format->Amask);
//	SDL_BlitSurface(oSurface, NULL, surface, NULL);
	YEP_ERROR_TEST(surface, "Cannot create a SDL_Surface when copying layer");
}

Layer::~Layer()
{
	SDL_FreeSurface(surface);
}

//string Layer::getName() const
//{
//	return name;
//}

SDL_Surface *Layer::getSurface() const
{
	return surface;
}

//void Layer::setName(string name)
//{
//	this->name = name;
//}

Layer & Layer::operator =(const Layer & other)
{
	if (&other != this)
	{
		SDL_FreeSurface(surface);
		surface = other.surface;
	}
	return *this;
}

void Layer::setSurface(SDL_Surface *surface)
{
	if (surface == this->surface)
		return;
	SDL_FreeSurface(this->surface);
	this->surface = surface;
}

} /* namespace yep */
